package com.bootdo.market.controller;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.market.dao.DuplicateDao;
import com.bootdo.market.domain.PlatformAdvunionDO;
import com.bootdo.market.service.PlatformAdvunionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 平台广告联盟
 *
 * @author jinse
 * @email market@jinse.com
 * @date 2019-04-25 18:02:02
 */

@Controller
@RequestMapping("/market/platformAdvunion")
public class PlatformAdvunionController {
    @Autowired
    private PlatformAdvunionService platformAdvunionService;
    @Autowired
    private DuplicateDao duplicateDao;

    @GetMapping()
    @RequiresPermissions("market:platformAdvunion:platformAdvunion")
    String PlatformAdvunion() {
        return "market/platformAdvunion/platformAdvunion";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("market:platformAdvunion:platformAdvunion")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<PlatformAdvunionDO> platformAdvunionList = platformAdvunionService.list(query);
        int total = platformAdvunionService.count(query);
        PageUtils pageUtils = new PageUtils(platformAdvunionList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("market:platformAdvunion:add")
    String add() {
        return "market/platformAdvunion/add";
    }

    @GetMapping("/edit/{id}")
    @RequiresPermissions("market:platformAdvunion:edit")
    String edit(@PathVariable("id") Integer id, Model model) {
        PlatformAdvunionDO platformAdvunion = platformAdvunionService.get(id);
        model.addAttribute("platformAdvunion", platformAdvunion);
        return "market/platformAdvunion/edit";
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("market:platformAdvunion:add")
    public R save(PlatformAdvunionDO platformAdvunion) {
        if (platformAdvunionService.save(platformAdvunion) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("market:platformAdvunion:edit")
    public R update(PlatformAdvunionDO platformAdvunion) {
        platformAdvunionService.update(platformAdvunion);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("market:platformAdvunion:remove")
    public R remove(Integer id) {
        if (platformAdvunionService.remove(id) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("market:platformAdvunion:batchRemove")
    public R remove(@RequestParam("ids[]") Integer[] ids) {
        platformAdvunionService.batchRemove(ids);
        return R.ok();
    }

    @RequestMapping(value = "/platformAdvunionJudgingUniqueAdd", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public R platformAdvunionJudgingUniqueAdd(HttpServletRequest request, @RequestParam Map<String, Object> params) {
        Map<String, Object> aa = duplicateDao.platformAdvunionJudgingUniqueAdd(params);
        if (aa == null) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @RequestMapping(value = "/platformAdvunionJudgingUniqueEdit", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public R platformAdvunionJudgingUniqueEdit(HttpServletRequest request, @RequestParam Map<String, Object> params) {
        Map<String, Object> aa = duplicateDao.platformAdvunionJudgingUniqueEdit(params);
        if (aa == null) {
            return R.ok();
        } else {
            return R.error();
        }
    }
}
